<template>
  <a-select
    show-search
    option-filter-prop="children"
    :placeholder="$t('upgradeType')"
    :allow-clear="clear"
    :mode="mode"
    :disabled="disabled"
    :maxTagCount="maxTagCount"
    v-model="selectedValue"
    :getPopupContainer="getPopupContainer"
  >
    <a-select-option
      v-for="(item, index) in upgradeTriggerType"
      :key="'upgradeType'+index"
      :value="item.value"
      :title="item.name"
    >{{ item.name }}</a-select-option>
  </a-select>
</template>
<script>
  import {mapState} from "vuex";
  export default {
    components: {

    },
    props: {
      mode: {
        type: String,
        default: 'default'
      },
      defaultValue: {
        type: [String, Array, Object, undefined],
        default () {
          return undefined
        }
      },
      query: {
        type: Object,
        default () {
          return null
        }
      },
      maxTagCount: {
        type: Number,
        default: 1
      },
      disabled: {
        type: Boolean,
        default: false
      },
      clear: {
        type: Boolean,
        default: false
      },
      appendToBody: {
        type: Boolean,
        default: false
      }
    },
    model: {
      prop: "defaultValue", //绑定的值，通过父组件传递
      event: "change" //自定义事件名
    },
    computed: {
      ...mapState({
        upgradeTriggerType: state => state.dict.upgradeTriggerTypeDictCode,
      }),
      selectedValue:{
        get() {
          return this.defaultValue;
        },
        set(val) {
          this.$emit('change', val);    // 触发
          this.changeOption(val)
        }
      }
    },
    data () {
      return {
        modelOptions: [],
      }
    },
    created () {
      this.$store.dispatch('getUpgradeTriggerTypeDictCodeData')
    },
    methods: {
      getPopupContainer (triggerNode) {
        if (!this.appendToBody && triggerNode) {
          return triggerNode.parentNode
        } else {
          return window.document.body
        }
      },
      changeOption (val) {
        let item = this.versionType.find(e => e.value === val);
        this.$emit('changeoption', val, item);
      },
    }
  }
</script>
